package org.hackystat.devcathlon.ui.page;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.PropertyModel;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.commons.panels.clock.ClockPanel;
import org.hackystat.devcathlon.ui.page.login.LoginPage;
import org.hackystat.devcathlon.ui.page.matches.MatchesPage;
import org.hackystat.devcathlon.ui.page.matches.browse.BrowsePage;
import org.hackystat.devcathlon.ui.page.matches.invitations.InvitationsPage;
import org.hackystat.devcathlon.ui.page.profile.ProfilePage;
import org.hackystat.devcathlon.ui.page.profile.browse.ProfileBrowsePage;
import org.hackystat.devcathlon.ui.page.profile.manage.ProfileManagePage;
import org.hackystat.devcathlon.ui.page.scoreboard.ScoreboardPage;
import org.hackystat.devcathlon.ui.page.scoreboard.halloffame.HallofFamePage;
import org.hackystat.devcathlon.ui.page.teams.TeamsPage;
import org.hackystat.devcathlon.ui.page.teams.invitations.TeamsInvitationPage;
import org.hackystat.devcathlon.ui.page.teams.manage.TeamsManageCreatePage;
import org.hackystat.devcathlon.ui.page.teams.manage.TeamsManagePage;
import org.hackystat.devcathlon.ui.page.teams.browse.TeamsBrowsePage;
import org.hackystat.devcathlon.ui.page.matches.manage.MatchesManagePage;
import org.hackystat.devcathlon.ui.page.matches.manage.creatematchpanel.CreateNewMatchPanel;

/**
 * Provides a base class with associated markup that all Devcathlon pages (except Login)
 * should inherit from. See http://wicket.apache.org/examplemarkupinheritance.html for an
 * explanation of how this works.
 * 
 * @author Philip Johnson
 */
public class DevcathlonBasePage extends WebPage {
  
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  
  /** Displays text at the bottom of the screen for user information. */
  protected String footerFeedback = "";

  /**
   * Create the DevcathlonBasePage.
   */
  public DevcathlonBasePage() {
    add(HeaderContributor.forCss(org.hackystat.devcathlon.ui.Start.class, 
        "page/style/boilerplate/screen.css", "screen"));
    add(HeaderContributor.forCss(org.hackystat.devcathlon.ui.Start.class, 
        "page/style/boilerplate/print.css", "print"));

    // Header logo
    add(new Image("logo",
        new ResourceReference(LoginPage.class, "devcathlon-header-logo.png")));
     
    /** Profile Menu */
    add(new Link("ProfileLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new ProfilePage());
      }
    });
    /** Profile Manage Submenu */
    add(new Link("ProfileManageLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new ProfileManagePage());
      }
    });
    /** Profile Browse Submenu */
    add(new Link("ProfileBrowseLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new ProfileBrowsePage());
      }
    });   

    add(new Link("TeamsLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new TeamsPage());
      }
    });
    
    add(new Link("TeamsBrowseLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new TeamsBrowsePage());
      }
    });    
    add(new Link("TeamsManageLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new TeamsManagePage());
      }
    });    
    add(new Link("TeamsInvitationLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        DevcathlonSession.get().getTeamsSession().clearSelectedTeam();
        setResponsePage(new TeamsInvitationPage());
      }
    });
    add(new Link("TeamsCreateLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new TeamsManageCreatePage());
      }
    });    
    
    add(new Link("MatchesLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new MatchesPage());
      }
    });
    add(new Link("MatchesManageLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new MatchesManagePage());
      }
    });
    add(new Link("BrowseLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new BrowsePage());
      }
    });
    add(new Link("InvitationsLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new InvitationsPage());
      }
    });
    
    add(new Link("CreateMatchLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new CreateNewMatchPanel());
      }
    });
    
    add(new Link("ScoreboardLink") {
      private static final long serialVersionUID = 1L;

      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new ScoreboardPage());
      }
    });
    
    add(new Link("HallofFameLink") {
      private static final long serialVersionUID = 1l;
      
      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new HallofFamePage());
      }
    });
    
    add(new Link("LogoutLink") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      /** Go to the home page after invalidating the session. */
      @Override
      public void onClick() {
        getSession().invalidate();
        setResponsePage(getApplication().getHomePage());
      }
    });
    
    add(new ClockPanel("clockPanel"));
    add(new Label("FooterFeedback", new PropertyModel(this, "footerFeedback")));
    add(new Label("UserEmail", new PropertyModel(DevcathlonSession.get(), "userEmail")));
  }
  
 
}
